function [pass ] = testAll()
%UNTITLED3 Summary of this function goes here
%   Detailed explanation goes here
    pass = 1;


%           1  2  3  4  5  6  7  8  9  10
    copy = [2  2  2  2  3  3  3  3  2  2;   %1
            2  3  3  2  2  3  3  3  2  2;   %2
            1  1  1  1  2  2  2  2  1  1;   %3
            2  2  3  3  3  3  3  3  2  2;   %4
            2  2  2  5  5  4  4  2  2  2;   %5
            1  1  3  3  4  4  4  1  1  1;   %6
            1  1  1  1  2  2  2  2  2  2;   %7
            1  1  1  1  1  2  2  2  2  2;   %8
            2  2  2  2  2  3  3  3  3  3];  %9
    
    trans = getTransitionVectors(copy);
    
    %             1     2     3     4     5     6     7     8     9
    trans_test = [0     0     0     2003  0     0     0     3002  0;    %1
                  2003  0     3002  0     2003  0     0     3002  0;    %2
                  0     0     0     1002  0     0     0     2001  0;    %3
                  0     2003  0     0     0     0     0     3002  0;    %4
                  0     0     2005  0     5004  0     4002  0     0;    %5
                  0     1003  0     3004  0     0     4001  0     0;    %6
                  0     0     0     1002  0     0     0     0     0;    %7
                  0     0     0     0     1002  0     0     0     0;    %8
                  0     0     0     0     2003  0     0     0     0];   %9
              
    hasTraitTest = [1, 4, 1; 2, 3, 1; 2, 4, 1; 3, 1, 1; 3, 2, 1; 4, 4, 1; 5, 4, 1; 5, 6, 1; 5, 7, 1;
                    6, 1, 1; 6, 4, 1; 6, 6, 1; 6, 2, 1; 7, 1, 1; 8, 1, 1; 9, 5, 1];
    
    if (size(trans, 1) ~= size(trans_test, 1) || size(trans, 2) ~= size(trans_test, 2))
        fprintf('ERROR: size of transition vectors wrong\n');
        pass = 0;
        return;
    end
    for i = 1:size(trans, 1)
        for j = 1:size(trans, 2)
            if (trans(i, j) ~= trans_test(i, j))
                fprintf('ERROR: transition error at %d, %d\n', i, j);
                pass = 0;
                return;
            end
        end
    end
        
    [traits, starts, ends] = collectAllCombinedTraits(trans);    
    traits_test = [2001, 2001, 2001, 2001, 2001, 2003, 2003, 2003, 2003, 2003, 2003, 2003, 3004, 3004, 4005]';
    starts_test = [-1,   -1,   -1,   7,    8,    1,    2,    2,    3,    4,    5,    5,    3,    4,    3   ]';
    ends_test =   [2,    4,    5,    -1,   -1,   3,    7,    8,    7,    8,    -1,   8,    7,    7,    5   ]';
    
    
    if (size(traits, 1) ~= size(traits_test, 1))
        fprintf('ERROR: number of traits wrong, R:%d, T:%d\n', size(traits, 1), size(traits_test, 1));
        pass = 0;
        return;
    end
    
    for i = 1:size(traits, 1)
        if (traits(i, 1) ~= traits_test(i, 1))
            fprintf('ERROR: trait mismatch\n');
            pass = 0;
            return;
        end
        if (starts(i, 1) ~= starts_test(i, 1))
            fprintf('ERROR: start mismatch\n');
            pass = 0; 
            return;
        end
        if (ends(i, 1) ~= ends_test(i, 1))
            fprintf('ERROR: end mismatch\n');
            pass = 0;
            return;
        end
    end
    
  
    [blendTraits] = blendCombinedTraits(traits, starts, ends);
    bc(:, 1) = blendTraits(:, 1);
    bs(:, 1) = blendTraits(:, 2);
    bsw(:, 1) = blendTraits(:, 3);
    be(:, 1) = blendTraits(:, 4);
    bew(:, 1) = blendTraits(:, 5);
    
    bc_test =  [2001, 2001, 2003, 2003, 2003, 3004, 4005]';
    bs_test =  [-1,   8,    1,    3,    5,    4,    3   ]';
    bsw_test = [0,    1,    0,    2,    0,    1,    0   ]';
    be_test =  [4,    -1,   3,    8,    -1,   7,    5   ]';
    bew_test = [2,    0,    0,    1,    0,    0,    0   ]';
    
    
    if (size(bc, 1) ~= size(bc_test, 1))
        fprintf('ERROR: blend size error, R:%d, T:%d\n', size(bc, 1), size(bc_test, 1));
        pass = 0;
        return;
    end
    
    for i = 1:size(bc, 1)
        if (bc_test(i, 1) ~= bc(i, 1))
            fprintf('ERROR: bc error\n');
            pass = 0;
            return;    
        end
        
        if (bs_test(i, 1) ~= bs(i, 1))
            fprintf('ERROR: bs error, idx:%d, R:%d, T:%d\n', i, bs(i, 1), bs_test(i, 1));
            pass = 0;
            return;
        end
        
        if (bsw_test(i, 1) ~= bsw(i, 1))
            fprintf('ERROR: bsw error\n');
            pass = 0;
            return;
        end
        
        if (be_test(i, 1) ~= be(i, 1))
            fprintf('ERROR: be error\n');
            pass = 0;
            return;
        end
        
        if (bew_test(i, 1) ~= bew(i, 1))
            fprintf('ERROR: bew error\n');
            pass = 0;
            return;
        end
    end
    
    hasTraitAnswers = zeros(size(bc, 1), size(trans, 1));
    for i = 1:size(hasTraitTest, 1)
        hasTraitAnswers(hasTraitTest(i, 2), hasTraitTest(i, 1)) = hasTraitTest(i, 3);
    end
        
    
    for i = 1:size(bc, 1)
        for j = 1:size(trans, 1)
            cell = j;
            trait = i;
            has = hasTraitAnswers(i, j);
            if (has ~= hasCombinedTrait(trans(cell, :), blendTraits(trait, :)))
                fprintf('ERROR: hasTrait error, cell:%d, trait:%d, A:%d, E:%d\n', cell, trait, ~has, has);
                pass = 0;
                return;
            end
        end
    end
    
end

